<template>
	<view class="content">
			<view v-if="isLogin">
				<image src="/static/my_normal.png" mode="" style="height: 85.33px;width: 85.33px;" class="headicon"></image>
				<view class="text-area" v-if="isLogin">
					<text class="title">{{name}}</text>
				</view>
			</view>
	
			<view v-if="!isLogin">
				<image  class="headicon" :src="userInfo.icon"></image>
				<view class="text-area">
					<button type="primary" size="mini" @click="toLogin">点击登录</button>
				</view>
			</view>
	
			<view style="margin: 20rpx; width: 100%;">
				<view class="entry">个人信息</view>
				<view class="entry">订单列表</view>
				<view class="entry">修改密码</view>
				<view class="entry">意见反馈</view>
			</view>
			<button type="primary" size="default" style="width: 100%;" :disabled="!isLogin" @click="logout">退出</button>
		</view>
</template>

<script>
	export default {
	    data() {
	        return {
	            userInfo: {
	                userid: null,
	                icon: '',
	                nickname: '',
	                username: null
	            },
	            isLogin: false,
	            name: ''
	        }
	    },
	    onLoad() {
	    },
	    onShow() {
	        this.getUserInfo();
	        const name = uni.getStorageSync('name');
	        if (name) {
	            this.name = name;
	            this.isLogin = true;
	        } else {
	            this.isLogin = false;
	        }
	    },
	    methods: {
	        logout() {
	            uni.removeStorageSync('userInfo');
	            uni.removeStorageSync('name');
	            this.isLogin = false;
	        },
	        toLogin() {
	            uni.navigateTo({
	                url: './login'
	            });
	        },
	        getUserInfo() {
	            let userInfo = uni.getStorageSync('userInfo');
	            if (userInfo) {
	                this.userInfo = userInfo;
	                this.isLogin = true;
	                console.log('用户已登录，读取成功');
	            } else {
	                this.userInfo.username = null;
	                this.userInfo.nickname = null;
	                this.userInfo.icon = '/static/my_normal.png';
	                this.isLogin = false;
	            }
	        },
	        online() {
	            uni.navigateTo({
	                url: './register'
	            });
	        }
	    }
	}
</script>

<style>
	.content {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 20rpx;
		}
	
		.headicon {
			height: 200rpx;
			width: 200rpx;
			margin-top: 80rpx;
			margin-left: auto;
			margin-right: auto;
			margin-bottom: 50rpx;
			border-radius: 50%;
		}
	
		.text-area {
			display: flex;
			justify-content: center;
		}
	
		.title {
			font-size: 36rpx;
			color: #8f8f94;
		}
	
		.entry {
			width: 100%;
			text-align: left;
			height: 3em;
			line-height: 3em;
			text-indent: 1em;
			border-top: #CCC solid 1rpx;
		}
	
		.entry:last-of-type {
			border-bottom: #CCC solid 1rpx;
		}
	
		.entry::after {
			content: '';
			background-image: url('/static/my.png');
			position: absolute;
			width: 50rpx;
			height: 50rpx;
			margin-top: 0.5em;
			background-size: contain;
			right: 50rpx;
		}
</style>